package common.liusany.admin.schedule;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import common.liusany.admin.entity.account.Email;
import common.liusany.admin.service.account.EmailManager;
import common.liusany.admin.utils.CommonAttribute;

/**
 * 被Spring的Quartz MethodInvokingJobDetailFactoryBean定时执行的普通Spring Bean.
 */
public class QuartzJob {

	private static Logger logger = LoggerFactory.getLogger(QuartzJob.class);
	
	private static final int maxResult = 1000;
	
	private List<Email> list = new ArrayList<Email>();

	@Resource
	EmailManager emailManager;

	/**
	 * 没隔一分钟修改邮件发送状态
	 */
	public void execute() {
		System.gc();
		emailManager.exeBatchUpdate();
		
	}
	
	/**
	 * 每隔30分钟 查询10000条数据 放入任务池
	 * @author:liufei
	 */
	public void exeAddSendTask(){
		
		logger.info("2分钟任务执行....");
		if(CommonAttribute.TASK_EXES_STATUS){
			
			
			list = emailManager.getEmailList(maxResult);
			
			logger.info("查询数据"+list.size()+"条");
			
			if (list != null && list.size() > 0)
			{
				for(Email email : list){
					emailManager.sendHtmlMail(email);
				}
			}
		}
	}
}
